#include "listD.h"

#include <iostream>
using namespace std;
    template <class list_type>
    ListD<list_type>::ListD()
    {
		ListSize=0;
		topList =0;
		BS = new list_type [size];
		cout << "ctor ListD" << endl;
    }
	
	template <class list_type>
	ListD<list_type>::ListD(const ListD& LS) {
		BS = new list_type [LS.size()];
		ListSize = LS.size();
		topList = 0;
		for (int i=0; i<size; i++) {
			BS[i] = LS.BS[i];
			topList++;
		}
	}

    template <class list_type>
    ListD<list_type>::~ListD() {
		if (BS) {
			for (int z=0; z<ListSize; z++) {
				delete BS[z];
			}
			delete [] BS;
		}
    }
	
	template <class list_type>
	ListD<list_type>& ListD<list_type>::operator=(const ListD& LS) {
		if (BS) {
			delete [] BS;
		}
		BS = new list_type [LS.size()];
		ListSize = LS.size();
		topList = 0;
		for (int i=0; i<size; i++) {
			BS[i] = LS.BS[i];
			topList++;
		}
	}
	
	template <class list_type>
	list_type ListD<list_type>::operator[](int z) const {
		return BS[z];
	}

    template <class list_type>
    void ListD<list_type>::push_back (list_type item)
    {
		ListD<list_type> LTemp (*this);
		if (BS) {delete [] BS;}
		ListSize = LTemp.size() + 1;
		topList = 0;
		for (int i=0; i<LTemp.size(); i++) {
			BS[i] = LTemp.BS[i];
			topList++;
		}
        BS [topList] = item;
        topList++;
    }

    template <class list_type>
    void ListD<list_type>::pop (list_type& item)
    {
		item = BS[topList];
        topList--;
    }
	
	template <class list_type>
    int ListD<list_type>::size ()
    {
		return ListSize;
    }
	
	
